module.exports = function ($scope, $state, $resource, $modal, toaster) {
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
	};
	$scope.pageInfo = {};
	$scope.pageInfo.pageNo = 1;		//当前页码
	$scope.pageInfo.pageSize = 10;	//每页显示几条
  // $scope.pageInfo.totalItems = 0;	//总条数
  $scope.pageInfo.type = '4';
	//卡列表
	$scope.loadlist = function () {
		$resource('/api/as/mc/shophelp/findHelp2List', {}, {}).save($scope.pageInfo, function (res) {
			if (res.errcode === 0) {
				$scope.beanList = res.data.results;
				$scope.pageInfo.totalItems = res.data.totalRecord;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
	}

	$scope.loadlist();


	//详情
	$scope.info = function (bean) {
		var modalInstance = $modal.open({
			template: require('../views/skwxFeedbackInfo.html'),
			controller: 'skwxFeedbackInfo',
			size: 'lg',
			resolve: {
				bean: function () {
					return bean;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function () {
			$scope.loadlist();
		});
	}

	$scope.imgclass = false;

	$scope.bigger = function () {
		console.log($scope.imgclass);
		$scope.imgclass = true;
	}

	$scope.smaller = function () {
		$scope.imgclass = false;
	}

	//上架
	$scope.up = function(info) {
		
		var para = {
			'id': info.id
    }
    console.log(info.profit_level1, info.profit_level2, info.profit_level3);
    if (info.profit_level1 + info.profit_level2 + info.profit_level3 == 100) {
        $resource('/api/as/mc/shopproduct/updateseestateone', {}, {}).save(para, function(res){
            if(res.errcode === 0){
              toaster.success({title: '', body: '上架成功。'});
              $scope.loadlist();
            }else{
              toaster.error({title: '', body: '上架失败请重试。'});
            }
        });
    } else {
        alert('三级分润不能为空');
    }
		
	}

	//下架
	$scope.down = function(info) {
		
		var para = {
			'id': info.id
		}
		$resource('/api/as/mc/shopproduct/updateseestatezero', {}, {}).save(para, function(res){
			if(res.errcode === 0){
				toaster.success({title: '', body: '下架成功。'});
				$scope.loadlist();
			}else{
				toaster.error({title: '', body: '下架失败请重试。'});
			}
		});
  }
  $scope.setclass = function (bean) {
      var modalInstance = $modal.open({
        template: require('../views/skwxAddClass.html'),
        controller: 'skwxAddClass',
        size: 'lg',
        resolve: {
          product_code: function () {
            return bean.product_code;
          }
        }
      });
      //关闭模态框刷新页面
      modalInstance.result.then(function () {
        $scope.loadlist();
      });
  }
  $scope.addSource = function(bean){
      var modalInstance = $modal.open({
        template: require('../views/skwxAddSource.html'),
        controller: 'skwxAddSource',
        size: 'lg',
        resolve: {
          bean: function () {
            return bean;
          }
        }
      });
      //关闭模态框刷新页面
      modalInstance.result.then(function () {
        $scope.loadlist();
      });
  }
};